package sctu.edu.java.year2016.team07.huangsuixin.day20160610.chapter12_3;

/**
 * Created by Huang Suixin on 2016/6/10.
 */


import java.io.*;
import java.util.Scanner;

/**
 * 3.编写程序，实现当用户输入姓名和密码是，将每一个姓名和密码加在文件中。
 */
public class Client {
    public static void main(String[] args) throws IOException {
        Scanner scan = new Scanner(System.in);
        System.out.print("输入用户名：");
        String name = scan.nextLine();
        System.out.print("输入密码：");
        String password = scan.nextLine();

        String path = "D:\\dev\\Test\\NameAndPassword.txt";
        File file = new File(path);
        try {
            if(file.exists()){
            }else{
                file.createNewFile();
            }
            FileWriter fw = new FileWriter(file,true);
            fw.write(name+" - ");
            fw.write(password);
            fw.write("\n");
            fw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try{
            System.out.println("文件当前记录的姓名，密码：");
            FileReader fr = new FileReader(file);
            char c[] = new char[1024];
            fr.read(c);
            System.out.println(c);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
}
